import gradeApi from 'api/grade'
// state
let state = {
  class: {},
  student: {}
}

// actions
const actions = {
  class ({ commit, state }, params) { // 获取列表
    return gradeApi.classList(params).then((json) => {
      commit('CLASS', {
        params: params,
        data: json.data
      })
    })
  },
  student ({ commit, state }, params) { // 获取大纲详情
    return gradeApi.studentList(params).then((json) => {
      commit('STUDENT', {
        params: params,
        data: json.data
      })
    })
  }
}
// mutations
const mutations = {
  CLASS (state, { data }) {
    if (data && data.list.length > 0) {
      data.list.forEach(item => {
        item.time = new Date(item.startTime).format('HH:mm-') + new Date(item.endTime).format('HH:mm')
      })
    }
    state.class = data
  },
  STUDENT (state, {data}) {
    state.student = data
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}
